<?php
/**
 * Created by PhpStorm.
 * User: mt
 * Date: 2018/10/13
 * Time: 15:45
 */

namespace App\Admin\Extensions;
use Encore\Admin\Admin;


class ScanPhoto
{
    protected $id;

    public function __construct($id, $status)
    {
        $this->id = $id;
        $this->status = $status;
    }

    protected function script()
    {
        return <<<SCRIPT
$('.grid-check-row').on('click', function () {
    if($(this).data('status')){
        var res = confirm('该用户已识别过，是否重新识别？')
        if(res){
            scanToFace($(this).data('id'));
        }
    }else{
       scanToFace($(this).data('id'));
    }
    
});
SCRIPT;
    }

    protected function render()
    {
        Admin::script($this->script());

        return "<a class='btn btn-xs btn-success fa fa-check grid-check-row' data-id='{$this->id}' data-status='{$this->status}'>识别</a>";
    }

    public function __toString()
    {
        return $this->render();
    }

}